import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
import seaborn as sns
from settings import *

plt.rcParams['font.sans-serif']=['SimHei'] #图中文字体设置为黑体
data=pd.read_csv(csv_file,encoding='utf8')
def price_destribution():
        price=list(map(lambda x:int(float(x.strip('元'))),data['price']))
        print(price)
        plt.figure('price destribute',facecolor='lightgray')
        plt.title('phone price', fontsize=20)
        plt.xlabel('price', fontsize=14)
        plt.ylabel('frequency', fontsize=14)
        plt.tick_params(labelsize=12)
        plt.grid(axis='y', linestyle=':')
        plt.hist(price,bins=10,range=(79,12000),edgecolor='steelblue',
                facecolor='deepskyblue', label='price')
        plt.legend()
        plt.show()

def location_sort():
        loc=list(data.groupby('location'))
        # print(len(loc[0][1]))
        dic={}
        for i in range(len(loc)):
                dic[loc[i][0]]=len(loc[i][1])
        sorted_dic=sorted(dic.items(),key=lambda x:x[1],reverse=True)
        # print(sorted_dic)
        city=[]
        num=[]
        for item in sorted_dic:
                city.append(item[0])
                num.append(item[1])
        plt.figure('sale location',facecolor='lightgray')
        plt.title('sale location---', fontsize=20)
        plt.xlabel('city', fontsize=14)
        plt.ylabel('num', fontsize=14)
        plt.tick_params(labelsize=12)
        plt.grid(axis='y', linestyle=':')
        plt.bar(city,num,edgecolor='steelblue',
                facecolor='deepskyblue')
        plt.legend()
        plt.show()
location_sort()